﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HtmlToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Browse_Click(object sender, EventArgs e)
        {
            OpenFileDialog browseFiles = new OpenFileDialog();
            browseFiles.ShowDialog();
            FilePath.Text = Path.GetDirectoryName(browseFiles.FileName);
        }

        private void Convert_Text_Click(object sender, EventArgs e)
        {
            var directory = Path.Combine(FilePath.Text, "text");
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            foreach (var file in Directory.EnumerateFiles(FilePath.Text))
            {
                var htmlText = File.ReadAllText(file);
                var convertedText = HtmltoTextConverter.StripTagsRegex(htmlText);
                if (convertedText.Trim() != string.Empty)
                {
                    File.WriteAllText(Path.Combine(directory, Path.GetFileNameWithoutExtension(file) + ".txt"), convertedText);
                }
            }

        }
    }
}
